


const state = () => ({
  tableArr:[],
  confirmArr:[],
  totalSelect:0,
  tpParams:{
    title:'',
    cateId:'',
    quesScore:{}
  },
  policyItem:[],
  bannerItem:{}
})

// mutations
const mutations = {
  clearTpParams (state){
    state.tpParams = {
      title:'',
      cateId:'',
      quesIds:[],
      quesScore:{}
    }
  },
  changeTpParams(state,obj){
    state.tpParams[obj.type] = obj.value
  },
  selectTabel(state,obj){
     if(obj.pageList.length==obj.selectList.length){
      state.tableArr=[...state.tableArr,...obj.selectList]
     }else{
      obj.pageList.map(item=>{
        let index = state.tableArr&&state.tableArr.findIndex(v=>{
          return v.id == item.id
        })
        if(index>=0){
          state.tableArr.splice(index,1)
        }
      })
      state.tableArr = [...state.tableArr,...obj.selectList]
     }
     state.tableArr = Array.from(new Set(state.tableArr))
     state.totalSelect = state.tableArr.length
  },
  clearTabel(state,num){
    state.tableArr =[]
    state.totalSelect = 0
  },
  showConfirm(state){
   state.tableArr = state.confirmArr
   state.totalSelect = state.tableArr.length
  },
  setConfirmArr(state,detailArr){
    if(detailArr&&detailArr.length>0){
      state.confirmArr = JSON.parse(JSON.stringify(detailArr))
    }else{
      state.confirmArr = JSON.parse(JSON.stringify(state.tableArr))
    }
   
  },
  clearConfirmArr(state){
    state.confirmArr=[]
  },
  setPolicyItem(state,arr){
    state.policyItem = arr
  },
  setBannerItem(state,obj){
    state.bannerItem = obj
  },
  clearBannerItem(state){
    state.bannerItem = {}
  }
}

// actions
const actions = {}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
